package com.jcy.jcyrxjava.timeselect;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ListView;
import android.widget.PopupWindow;

import com.jcy.jcyrxjava.R;

import java.util.ArrayList;
import java.util.List;

public class SelectTimeActivity extends AppCompatActivity {
    private PopupWindow mPopupWindow;
    List<String>mData= new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_select_time);
        initData();
    }

    private void initData() {
        for (int i = 0; i < 10; i++) {
            mData.add((i+1)+"月"+(i+1)+"日");
        }
    }

    public void onClick(View view) {
        showPop();
    }

    private void showPop() {
        // 设置布局文件
        View bottomView = View.inflate(this, R.layout.time_item, null);
        //mPopupWindow.setContentView(LayoutInflater.from(getActivity()).inflate(R.layout.pop_layot, null));
        mPopupWindow = new PopupWindow(bottomView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        mPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
        mPopupWindow.setOutsideTouchable(true);
        mPopupWindow.setFocusable(true);
        WheelView main_wv = bottomView.findViewById(R.id.main_wv);
        main_wv.setOffset(1);
        main_wv.setItems(mData);
        main_wv.setColorCheckValueFrame("#83cde6");
        main_wv.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
            @Override
            public void onSelected(int selectedIndex, String item) {
//                Logger.d(TAG, "selectedIndex: " + selectedIndex + ", item: " + item);
                Log.i("steve", "selectedIndex: " + selectedIndex + ", item: " + item);
//                currentItemName = item;
            }
        });
        Button bt_cancle = bottomView.findViewById(R.id.bt_cancle);
        bt_cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mPopupWindow.dismiss();
            }
        });
        Button bt_sure = bottomView.findViewById(R.id.bt_sure);
        bt_sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.alpha = 0.5f;
        getWindow().setAttributes(lp);
        mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {

            @Override
            public void onDismiss() {
                WindowManager.LayoutParams lp = getWindow().getAttributes();
                lp.alpha = 1f;
                getWindow().setAttributes(lp);
            }
        });
//        mPopupWindow.setAnimationStyle(R.style.pop_style);
//        mPopupWindow.showAsDropDown(bar_action, UIUtils.dip2px(300), 0);
        mPopupWindow.showAtLocation(getWindow().getDecorView(), Gravity.CENTER, 0, 0);
    }

}
